/*
 * @Descripttion: 
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-23 11:03:01
 * @LastEditTime: 2023-02-21 09:28:24
 */
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import Opt from '@/components/dt/info/Opt.js'
import planOpt from '@/biz/option/plan.js'
import dateOpt from '@/biz/option/date.js'

let _this = null

class Column extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [{
      title: '签约单编号',
      field: 'contractCode',
      minWidth: 150,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '签约单编号'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: {
          title: '签约单编号',
          key: 'orderCode',
          placeholder: '请输入至少4位签约单编号',
          input: {},
          check: (val) => {
            if (val.orderCode.length < 4) {
              _this.$Message.warning('请输入至少4位签约单编号。')
            }
            return !(val.orderCode.length < 4)
          }
        },
      }
    },
    {
      title: '所属分公司',
      field: 'orgCompanyName',
      minWidth: 180,
      cell: {
        text: {
          lineClamp: 2,
          webkitBoxOrient: 'vertical',
          display: '-webkit-box',
          whiteSpace: 'inherit'
        }
      }
    },
    {
      title: '所属案场',
      field: 'housesName',
      minWidth: 180,
      cell: {
        text: {
          lineClamp: 2,
          webkitBoxOrient: 'vertical',
          display: '-webkit-box',
          whiteSpace: 'inherit'
        }
      }
    },
    {
      title: '所属产品',
      field: 'productName',
      minWidth: 180,
      cell: {
        text: {
          lineClamp: 2,
          webkitBoxOrient: 'vertical',
          display: '-webkit-box',
          whiteSpace: 'inherit'
        }
      }
    },
    {
      title: '产品类型',
      field: 'productType',
      minWidth: 120,
      cell: {
        text: {
          type: 'dict',
          key: 'productType'
        }
      }
    },
    {
      minWidth: 150,
      field: 'counselorStr',
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '归属顾问'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: nameOpt.createCounselorPeople({
          key: 'counselorId',
          title: '归属顾问',
          to: (val) => {
            return {
              counselorId: val.userId
            }
          }
        })
      }
    },
    {
      title: '签约状态',
      field: 'showStatus',
      minWidth: 150,
      cell: (item) => {
        return {
          text: {
            type: 'dict',
            key: 'status',
            color: item.showStatus == '10102' ? '#D9001B' : '#515a6e'
          }
        }
      }
    },
    {
      title: '客户姓名',
      field: 'customerName',
      minWidth: 120,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '客户姓名'),
          ])]
        },
        default: (params, h) => {
          return table.cell.btn(_this, h, {
            title: params.row.customerName,
            event: 'onLinkUser',
            data: params.row
          })
        }
      },
      header:_this.countType?false:{
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {},
        },
      }
    },
    {
      title: '客户手机号',
      field: 'customerPhone',
      minWidth: 130,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '客户手机号'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: {
          title: '客户手机号',
          key: 'customerPhone',
          placeholder: '请输入至少4位客户手机号',
          input: {},
          check: (val) => {
            if (val.customerPhone.length < 4) {
              _this.$Message.warning('请输入至少4位客户手机号。')
            }
            return !(val.customerPhone.length < 4)
          }
        },
      }
    },
    {
      title: '签约房源',
      field: 'roomName',
      minWidth: 180,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '签约房源'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: {
          title: '签约房源',
          key: 'roomCode',
          placeholder: '请输入房间号',
          input: {},
        },
      }
    },
    {
      title: '面积（㎡）',
      field: 'roomArea',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '签约单价（元）',
      field: 'unitPrice',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '签约总价（元）',
      field: 'totalPrice',
      minWidth: 150,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '签约日期',
      field: 'contractDate',
      minWidth: 180,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '签约日期'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: dateOpt.range({
          title: '签约日期',
          startKey: 'contractStartDate',
          endKey: 'contractEndDate',
          disabled: (date) => {
            return date.valueOf() < new Date(_this.resolveTime.startTime)
              .getTime() ||
              date.valueOf() > new Date(_this.resolveTime.endTime).getTime()
          },
        }),
      },
    },
    {
      title: '退签日期',
      field: 'backContractDate',
      minWidth: 180,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '退签日期'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: dateOpt.range({
          title: '退签日期',
          startKey: 'backContractStartDate',
          endKey: 'backContractEndDate',
          disabled: (date) => {
            return date.valueOf() < new Date(_this.resolveTime.startTime)
              .getTime() ||
              date.valueOf() > new Date(_this.resolveTime.endTime).getTime()
          },
        }),
      },
    },
    {
      title: '认购日期',
      field: 'subscriptionDate',
      minWidth: 180,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '认购日期'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: dateOpt.range({
          title: '认购日期',
          startKey: 'subStartTime',
          endKey: 'subEndTime',
          disabled: (date) => {
            return date.valueOf() < new Date(_this.resolveTime.startTime)
              .getTime() ||
              date.valueOf() > new Date(_this.resolveTime.endTime).getTime()
          },
        }),
      },
    },
    {
      title: '渠道名称',
      field: 'channelName',
      minWidth: 120,
    },
    {
      title: '合作类型',
      field: 'cooperationType',
      minWidth: 120,
      // cell: {
      //   text: {
      //     type: 'dict',
      //     key: 'cooperationTypeFinal'
      //   }
      // }
    },
    {
      field: 'channelCostValue',
      title: '渠道费用(元)',
      width: 130,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      field: 'planName',
      title: '打法名称',
      width: 130,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '打法名称'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: planOpt.createNoBuild({
          key: 'planIds',
          title: '打法名称',
        })
      }
    },
    {
      title: '签约人',
      field: 'contractorName',
      minWidth: 150,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '签约人'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: nameOpt.createNoBuildContractor({
          key: 'contractorId',
          title: '签约人',
          from: () => {
            let info = _this.$dt.memory.get('conSumOrder_params')
            if (info && info.workNo) {
              return {
                value: info.workNo,
                label: info.userName + '（' + info.workNo + '）',
                userId: info.userId
              }
            } else {
              return null
            }
          },
          to: (info) => {
            return {
              contractorId: info.userId
            }
          }
        })
      }
    },
    {
      title: '签约单提交是否及时',
      field: 'isBackTimely',
      minWidth: 180,
      header:_this.countType?false:{
        filter: {
          title: '签约单提交是否及时',
          key: 'isBackTimely',
          placeholder: '请选择',
          select: {
            options: [{
              value: '及时',
              key: '1'
            }, {
              value: '不及时',
              key: '0'
            }],
            multiple:true
          },
          data:{
            from: (info) => {
              return null
            },
          }
        },
      },
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '签约单提交是否及时'),
          ])]
        },
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.isBackTimely == 1 ? '及时' : params.row.isBackTimely == 0 ? '不及时' : ''
          })
        }
      }
    },
    {
      title: '累计到账房款（元）',
      field: 'accumulateMoney',
      minWidth: 180,
      cell: {
        text: {
          type: 'number'
        }
      }
    }, {
      title: '剩余未到账房款（元）',
      field: 'remainingAmount',
      minWidth: 180,
      cell: {
        text: {
          type: 'number'
        }
      }
    },
    {
      title: '全款到账日期',
      field: 'predictAccountDate',
      minWidth: 180,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '全款到账日期'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: dateOpt.range({
          title: '全款到账日期',
          startKey: 'accountStartTime',
          endKey: 'accountEndTime',
          disabled: (date) => {
            return date.valueOf() < new Date(_this.resolveTime.startTime)
              .getTime() ||
              date.valueOf() > new Date(_this.resolveTime.endTime).getTime()
          },
        }),
      }
    },
    {
      title: '交房日期',
      field: 'dealRoomDate',
      minWidth: 150,
      slots: {
        header: (params, h) => {
          return [h('div', [
            h('span', '交房日期'),
          ])]
        }
      },
      header:_this.countType?false:{
        filter: dateOpt.range({
          title: '交房日期',
          startKey: 'dealRoomStartDate',
          endKey: 'dealRoomEndDate',
          disabled: (date) => {
            return date.valueOf() < new Date(_this.resolveTime.startTime)
              .getTime() ||
              date.valueOf() > new Date(_this.resolveTime.endTime).getTime()
          }
        })
      },
    },
    {
      title: '操作',
      fixed: 'right',
      width: 100,
      align: 'center',
      slots: {
        default: (params, h) => {
          let btns = []
          btns.push({
            title: _this.unlocking('0104030300') ? '查看' : '',
            event: 'viewFun',
            data: params.row
          })
          return table.cell.btns(_this, h, btns)
        }
      }
    }]
  }

}

export default Column